package com.defysoft.waukidsschool;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

public class JsonParser implements PublicConstant, Data_Type, Custom_Data_Type {
	
	
	public static ArrayList<CheckStudent> StartScanMode(String message) {

		ArrayList<CheckStudent> list = new ArrayList<CheckStudent>();
		CheckStudent checkStudent;
		JSONObject jsonObject;
		try {
			JSONArray jsonArray = new JSONArray(message);
			for (int i = 0; i < jsonArray.length(); i++) {
				jsonObject = jsonArray.getJSONObject(i);
				checkStudent = new CheckStudent();
				if (jsonObject != null) {
					if (jsonObject.has("stu_code")) {
						checkStudent.stu_code = jsonObject
								.getString("stu_code");
					}
					if (jsonObject.has("stu_name")) {
						checkStudent.stu_name = jsonObject
								.getString("stu_name");
					}
					if (jsonObject.has("stu_cla")) {
						checkStudent.stu_cla = jsonObject
								.getString("stu_cla");
					}
					if (jsonObject.has("stu_cla_name")) {
						checkStudent.stu_cla_name = jsonObject
								.getString("stu_cla_name");
					}
					if (jsonObject.has("bea_id")) {
						checkStudent.bea_id = jsonObject
								.getString("bea_id");
					}
				}
				list.add(checkStudent);
			}
		} catch (Exception e) {
			return list;
		}
		return list;
	}
	
	public static ArrayList<CheckStudentTwo> StartScanModeTwo(String message) {

		ArrayList<CheckStudentTwo> list = new ArrayList<CheckStudentTwo>();
		CheckStudentTwo checkStudentTwo;
		JSONObject jsonObject;
		try {
			JSONArray jsonArray = new JSONArray(message);
			for (int i = 0; i < jsonArray.length(); i++) {
				jsonObject = jsonArray.getJSONObject(i);
				checkStudentTwo = new CheckStudentTwo();
				if (jsonObject != null) {
					if (jsonObject.has("stu_code")) {
						checkStudentTwo.stu_code = jsonObject
								.getString("stu_code");
					}
					if (jsonObject.has("stu_name")) {
						checkStudentTwo.stu_name = jsonObject
								.getString("stu_name");
					}
					if (jsonObject.has("bea_id")) {
						checkStudentTwo.bea_id = jsonObject
								.getString("bea_id");
					}
					checkStudentTwo.uptime=System.currentTimeMillis ( ); 
				}
				list.add(checkStudentTwo);
			}
		} catch (Exception e) {
			return list;
		}
		return list;
	}
}// CLASS_END
